//导入需要的对象
const userTelService = require("../service/userTelService")
const express = require('express');

const router = express.Router();
const PATH = '/userTel'

router.get('/hello', function (req, res) {
    res.send('hello userTel')
})

router.get('/queryAll', async (req, res) => {
    let data = await userTelService.queryAll()
    res.json(data)
})

router.get('/queryByPageAll', async (req, res) => {
    //取参数
    let pageSize = parseInt(req.query.pageSize);
    let currentPageNo = parseInt(req.query.currentPageNo);
    let offset = (currentPageNo - 1) * pageSize;
    //查分页
    let data = await userTelService.queryByPageAll(offset, pageSize);
    let countData = await userTelService.queryByCountUserTel();
    const result = {success:true, message:'查询成功', data:data, count:countData[0].countNum};
    //返回数据{success:true, message:success, data:[...], count:100}
    // const result = {};
    res.json(result)
})

router.get('/queryByPageUserTel', async (req, res) => {
    //取参数
    let pageSize = parseInt(req.query.pageSize);
    let currentPageNo = parseInt(req.query.currentPageNo);
    let offset = (currentPageNo - 1) * pageSize;
    //查分页
    let data = await userTelService.queryByPageUserTel(offset, pageSize);
    let countData = await userTelService.queryByCountUserTel();
    const result = {success:true, message:'查询成功', data:data, count:countData[0].countNum};
    //返回数据{success:true, message:success, data:[...], count:100}
    // const result = {};
    res.json(result)
})


function queryById(id) {
    return userTelService.queryById(id)
}



module.exports = (app) => {
    app.use(PATH, router)
}